package cn.gson.crm.model.service;

import cn.gson.crm.model.dao.OrderDao;
import cn.gson.crm.model.dao.SalesAtDao;
import cn.gson.crm.model.mapper.OrderMapper;
import cn.gson.crm.model.mapper.SalesAtMapper;
import cn.gson.crm.model.pojos.Employee;
import cn.gson.crm.model.pojos.SalesAt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.*;

@Service
@Transactional(rollbackFor = Exception.class)
public class SalesAtService {
    @Autowired
    SalesAtDao salesAtDao;
    @Autowired
    SalesAtMapper salesAtMapper;
    @Autowired
    OrderDao orderDao;
    //统计图1(年份)
    public Map<String ,Object> selectSalesAt(String salesAttime){
       List<SalesAt> salesAts=salesAtMapper.selectSalesAt();
       Map<String,Object> map=new HashMap<>();
       List<Integer> aa=new ArrayList<>();//销售目标金额
       List<Integer> bb=new ArrayList<>();//销售业绩金额
       List<String> cc=new ArrayList<>();//姓名

       for(int i=0;i<salesAts.size();i++){
           System.err.println("业绩:"+orderDao.selecttwo(salesAts.get(i).getEmployeeByYgId(),"%"+salesAttime+"%"));
           bb.add(orderDao.selectone(salesAts.get(i).getEmployeeByYgId(),"%"+salesAttime+"%"));
           aa.add(salesAtDao.selectSalesAt2(salesAts.get(i).getEmployeeByYgId(),"%"+salesAttime+"%"));
           cc.add(salesAts.get(i).getEmployeeByYgId().getYname());
       }
       map.put("aa",aa);
       map.put("bb",bb);
       map.put("cc",cc);
       return map;
    }
    //统计图(月份)
    public Map<String ,Object> selectSalesAt2(String salesAttime){
        List<SalesAt> salesAts=salesAtMapper.selectSalesAt();
        Map<String,Object> map=new HashMap<>();
        List<Integer> aa=new ArrayList<>();//销售目标金额
        List<Integer> bb=new ArrayList<>();//销售业绩金额
        List<String> cc=new ArrayList<>();//姓名

        for(int i=0;i<salesAts.size();i++){
            System.err.println("业绩:"+orderDao.selecttwo(salesAts.get(i).getEmployeeByYgId(),"%"+salesAttime+"%"));
            System.err.println("目标:"+salesAtDao.selectSalesAt4(salesAts.get(i).getEmployeeByYgId(),"%"+salesAttime+"%"));
            bb.add(orderDao.selecttwo(salesAts.get(i).getEmployeeByYgId(),"%"+salesAttime+"%"));
            aa.add(salesAtDao.selectSalesAt4(salesAts.get(i).getEmployeeByYgId(),"%"+salesAttime+"%"));
            cc.add(salesAts.get(i).getEmployeeByYgId().getYname());
        }
        map.put("aa",aa);
        map.put("bb",bb);
        map.put("cc",cc);
        return map;
    }
    //统计图(日期)
    public Map<String ,Object> selectSalesAt3(String salesAttime){
        List<SalesAt> salesAts=salesAtMapper.selectSalesAt();
        Map<String,Object> map=new HashMap<>();
        List<Integer> aa=new ArrayList<>();//销售目标金额
        List<Integer> bb=new ArrayList<>();//销售业绩金额
        List<String> cc=new ArrayList<>();//姓名

        for(int i=0;i<salesAts.size();i++){
            bb.add(orderDao.selectthere(salesAts.get(i).getEmployeeByYgId(),"%"+salesAttime+"%"));
            aa.add(salesAtDao.selectSalesAt6(salesAts.get(i).getEmployeeByYgId(),"%"+salesAttime+"%"));
            cc.add(salesAts.get(i).getEmployeeByYgId().getYname());
        }
        map.put("aa",aa);
        map.put("bb",bb);
        map.put("cc",cc);
        return map;
    }
    //查询员工销售
    public List<SalesAt> salesAtList2(){
        return salesAtMapper.selectSalesAt2();
    }
    //新增销售目标
    public void addsalesAt(SalesAt salesAt){
        salesAtDao.save(salesAt);
    }
    //查询员工表
    public List<Employee> employeeList(){
        return  salesAtMapper.selectEmployee();
    }

    //主页统计图查询销售目标
    public Map<String,Object>  selectvalue2(){
        Map<String,Object> map=new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        Date date=new Date();
        System.out.println(sdf.format(date));
        Date date1=new Date();
        System.out.println(sdf.format(date1));
        List<String> aa=new LinkedList<>();
        List<Integer>  bb=new LinkedList<>();
        List<String> dd=new LinkedList<>();
        List<Integer> ff=new LinkedList<>();
        String ee="";
        String cc="";
        //判断月份
        for(int i=1;i<13;i++){
            if(i<10){
             cc= sdf.format(date)+"-"+0+i;
             ee= sdf.format(date)+"-"+0+i;
            }
            else {
             cc= sdf.format(date)+"-"+i;
             ee= sdf.format(date)+"-"+i;
            }
           aa.add(cc);
           dd.add(ee);
           bb.add(salesAtDao.selectSaleszhu1(aa.get(i-1)));
           ff.add(orderDao.selectMoney5(dd.get(i-1)));
           map.put("va",bb);
           map.put("vb",ff);
        }
        return map;
    }
    //主页统计图查询销售目标2
    public Map<String,Object>  selectvalue3(){
        Map<String,Object> map=new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        Date date=new Date();
        System.out.println(sdf.format(date));
        Date date1=new Date();
        System.out.println(sdf.format(date1));
        List<String> aa=new LinkedList<>();
        List<Integer>  bb=new LinkedList<>();
        List<String> dd=new LinkedList<>();
        List<Integer> ff=new LinkedList<>();
        String ee="";
        String cc="";
        //判断月份
        for(int i=1;i<13;i++){
            if(i<10){
                cc= sdf.format(date)+"-"+0+i;
                ee= sdf.format(date)+"-"+0+i;
            }
            else {
                cc= sdf.format(date)+"-"+i;
                ee= sdf.format(date)+"-"+i;
            }
            aa.add(cc);
            dd.add(ee);
            bb.add(salesAtDao.selectSaleszhu3(aa.get(i-1)));
            ff.add(orderDao.selectMoney5(dd.get(i-1)));
            map.put("va",bb);
            map.put("vb",ff);
        }
        return map;
    }
    //主页统计图查询销售目标3
    public Map<String,Object>  selectvalue4(){
        Map<String,Object> map=new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm");
        Date date=new Date();
        System.out.println(sdf.format(date));
        Date date1=new Date();
        System.out.println(sdf.format(date1));
        List<String> aa=new LinkedList<>();
        List<Integer>  bb=new LinkedList<>();
        List<String> dd=new LinkedList<>();
        List<Integer> ff=new LinkedList<>();
        String ee="";
        String cc="";
        //判断月份
        for(int i=1;i<13;i++){
            if(i<10){
                cc= sdf.format(date)+"-"+0+i;
                ee= sdf.format(date)+"-"+0+i;
            }
            else {
                cc= sdf.format(date)+"-"+i;
                ee= sdf.format(date)+"-"+i;
            }
            aa.add(cc);
            dd.add(ee);
            bb.add(salesAtDao.selectSaleszhu4(aa.get(i-1)));
            ff.add(orderDao.selectMoney5(dd.get(i-1)));
            map.put("va",bb);
            map.put("vb",ff);
        }
        return map;
    }
    //主页统计图查询销售目标4
    public Map<String,Object>  selectvalue5(){
        Map<String,Object> map=new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
        Date date=new Date();
        System.out.println(sdf.format(date));
        Date date1=new Date();
        System.out.println(sdf.format(date1));
        List<String> aa=new LinkedList<>();
        List<Integer>  bb=new LinkedList<>();
        List<String> dd=new LinkedList<>();
        List<Integer> ff=new LinkedList<>();
        String ee="";
        String cc="";
        //判断月份
        for(int i=1;i<13;i++){
            if(i<10){
                cc= sdf.format(date)+"-"+0+i;
                ee= sdf.format(date)+"-"+0+i;
            }
            else {
                cc= sdf.format(date)+"-"+i;
                ee= sdf.format(date)+"-"+i;
            }
            aa.add(cc);
            dd.add(ee);
            bb.add(salesAtDao.selectSaleszhu5(aa.get(i-1)));
            ff.add(orderDao.selectMoney5(dd.get(i-1)));
            map.put("va",bb);
            map.put("vb",ff);
        }
        return map;
    }
}
